package all.com.jinyongqunxiax.model.mod;

import com.randy.fundation.JxAssert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import all.com.jinyongqunxiax.BuildConfig;
import androidx.annotation.NonNull;
import jy.game.components.wuxue.pojo.JyInternalSkill;
import jy.game.tools.BasePojoManager;

public class SkillInternalManager {
    public Map<String, JyInternalSkill> map  = new HashMap<>();
    public List<JyInternalSkill>        list = new ArrayList<>();
    String xmlPath;

    public SkillInternalManager(@NonNull String xmlPath) {
        this.xmlPath = xmlPath;
    }

    BasePojoManager<JyInternalSkill> manager;

    public String load() {
        map.clear();
        list.clear();

        manager = BasePojoManager.build(xmlPath, JyInternalSkill.class);
        list = manager.datas;
        if (!manager.success()) {
            return manager.message;
        }
        StringBuilder message = new StringBuilder(getClass().getSimpleName());

        for (JyInternalSkill item : list) {
            if (map.containsKey(item.name)) {
                message.append("发现重复:").append(item.name);
                continue;
            }
            map.put(item.name, item);
        }


        return manager.message;
    }
//    public String load() {
//        try {
//            map.clear();
//            list.clear();
//            File file = new File(xmlPath);
//
//            Serializer serializer = new Persister();
//            Root       root       = serializer.read(Root.class, file);
//            assert !BuildConfig.DEBUG || !root.models.isEmpty();
//            list = root.models;
//            for (Model model : list) {
//                map.put(model.name, model);
//            }
//            if (BuildConfig.DEBUG) {
//                assert map.entrySet().size() == list.size();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return e.getMessage();
//        }
//        return "";
//    }
//
//    /**
//     * <internal_skill attack="0.5" critical="0" defence="0" hard="2" icon="icon_neigong_002" info="血刀门的入门心法，只重攻不重防" name="血刀心法" yang="50" yin="50">
//     * <trigger argvs="根骨,20" lv="10" name="attribute"/>
//     * <trigger argvs="血刀大法,100" lv="14" name="powerup_skill"/>
//     * <trigger argvs="血刀大法,100" lv="18" name="powerup_skill"/>
//     * <trigger argvs="血海魔功,100" lv="20" name="powerup_internalskill"/>
//     * </internal_skill>
//     */
//    static public class Root {
//        @ElementList(inline = true) List<Model> models;
//    }
//
//    @ wx.xml.simpleframework.xml.Root(name = "internal_skill")
//    static public class Model {
//        public @Attribute String name;
//        public @Attribute String icon;
//        public @Attribute String info;
//
//        public @Attribute float  attack;
//        public @Attribute float  critical;
//        public @Attribute float  defence;
//        public @Attribute int    hard;
//        public @Attribute int    yin;
//        public @Attribute int    yang;
//
//        public @ElementList(inline = true, required = false) List<Trigger> triggers;
//        public @ElementList(inline = true, required = false) List<Unique>  uniques;
//    }
}
